import React,{Component} from 'react';
import {connect} from 'dva'
import SelectAvatar from '../bossinfo/components/selectorAvatar'
import {NavBar,Icon ,InputItem,TextareaItem,Button,WhiteSpace} from 'antd-mobile'
import {Redirect} from 'dva/router'
class bossinfo extends Component{
    constructor(){
        super();
        this.state = {
            avatar:'',
            title:'',
            company:'',
            money:'',
            desc:''
        }
    }
    handleAvatar(imgname){
        this.setState({
            avatar:imgname
        })
        //console.log(imgname)
    }
    onChange(key,v){
        this.state[key] = v
    }
    updateBossInfo(){
        this.props.dispatch({type:'user/updataBossInfo',payload:this.state});
    }
    render(){
        return(
            <React.Fragment>
                {/* 重定向 */}
                {this.props.redirectPath? <Redirect to={this.props.redirectPath} />:null}
                {/* 头部 */}
                <NavBar
                    mode="dark"
                    leftContent="Back"
                    rightContent={[
                        <Icon key="0" type="search" style={{ marginRight: '16px' }} />,
                        <Icon key="1" type="ellipsis" />,
                    ]}
                    >NavBar</NavBar><WhiteSpace />
                {/* 组件传值 */}
                <SelectAvatar handleAvatar ={this.handleAvatar.bind(this)}></SelectAvatar>
                <InputItem onChange={(v)=>{this.onChange('title',v)}}>
                    招聘职位
                </InputItem><WhiteSpace />
                <InputItem onChange={(v)=>{this.onChange('company',v)}}>
                    公司名称
                </InputItem><WhiteSpace />
                <InputItem onChange={(v)=>{this.onChange('money',v)}}>
                    职位薪资
                </InputItem><WhiteSpace />
                <TextareaItem
					onChange={(v)=>this.onChange('desc',v)}
					rows={3}
					autoHeight
					title='职位要求'
				>	
				</TextareaItem>
                <WhiteSpace />
                <Button type="primary" onClick={()=>{this.updateBossInfo()}}>提交</Button>
            </React.Fragment>
        )
    }
}

const mapStateProps = (state)=>{
    return{
        redirectPath:state.user.redirectPath
    }
}
export default connect(mapStateProps)(bossinfo);